﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Tailor_Measurement : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loaddata();
        }
    }

    private void loaddata()
    {
        string sql = @"
SELECT [ProductID] as ID
      ,[ProductName] as Name  ,ExtraField1 
  FROM Tailor_Product";

        DataSet ds = CommonManager.SQLExec(sql);
        gvItems.DataSource = ds.Tables[0];
        gvItems.DataBind();
    }

    protected void lbSelect_Click(object sender, EventArgs e)
    {
        LinkButton linkButton = new LinkButton();
        linkButton = (LinkButton)sender;
        
        string sql = @"
SELECT [ProductID] as ID
      ,[ProductName] as Name  ,ExtraField1 
  FROM Tailor_Product where [ProductID]=" + linkButton.CommandArgument;
        DataSet ds = CommonManager.SQLExec(sql);

        hfID.Value = ds.Tables[0].Rows[0][0].ToString();
        txtName.Text = ds.Tables[0].Rows[0][1].ToString();
        txtCharge.Text = ds.Tables[0].Rows[0][2].ToString();

    }
    protected void lbDelete_Click(object sender, EventArgs e)
    {
        LinkButton linkButton = new LinkButton();
        linkButton = (LinkButton)sender;
        
        string sql = "Delete [Tailor_Product]   where [ProductID]=" + linkButton.CommandArgument;
         
        CommonManager.SQLExec(sql);
        loaddata();
        
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string sql="";
        if (hfID.Value == "")
        {
            sql = @"
INSERT INTO [Tailor_Product]
           ([ProductName]
           ,[ExtraField1]
           ,[ExtraField2]
           ,[ExtraField3]
           ,[ExtraField4]
           ,[ExtraField5])
     VALUES(N'" + txtName.Text + @"',N'" + txtCharge.Text + @"','','','','')
";
        }
        else
        {
            sql = "update [Tailor_Product] set [ProductName]=N'" + txtName.Text + @"', [ExtraField1]=N'" + txtCharge.Text + @"'  where [ProductID]=" + hfID.Value;
            hfID.Value = "";
        }
        txtName.Text = "";
        txtCharge.Text = "";
        CommonManager.SQLExec(sql);
        loaddata();
    }
    protected void ddlItem_SelectedIndexChanged(object sender, EventArgs e)
    {
        loaddata();
    }
}